#pragma once
#include <functional>
#include <string>
#ifdef ERROR
#undef ERROR
#endif

enum LogLevel {DEBUG = -1, INFO = 0, WARNING,ERROR };

namespace custom {
class LogMessageImpl;

// 日志等级
class Logging {
public:
    // 获取单例实例
    static Logging &getInstance();

    // 设置日志回调
    void setLoggerCallback(std::function<void(int, const std::string &, int, const std::string &)> callback);

    // 打印日志
    void log(int level, const std::string &file, int line, const std::string &msg);

private:
    // 私有构造函数和析构函数 (单例模式)
    Logging() = default;
    ~Logging() = default;

    // 禁用拷贝和赋值
    Logging(const Logging &) = delete;
    Logging &operator=(const Logging &) = delete;

    // 日志回调函数
    std::function<void(int, const std::string &, int, const std::string &)> logCallback;
};

class LogMessage {
public:
    LogMessage(int level, const char *file, int line);

    ~LogMessage();

    std::ostream &Os();

private:
    LogMessageImpl *impl_;
};


} // namespace custom
#define CLOG(level) custom::LogMessage(level, __FILE__, __LINE__).Os()
